package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.common.entity.PageDTO;
import com.boss.common.util.PageUtils;
import com.boss.framework.dto.PaginationDTO;
import com.boss.salary.entity.AgencyVerify;
import com.boss.salary.service.IAgencyVerifyService;
import com.boss.sys.ca.user.dto.UserDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/agencyStopAuditController")
public class AgencyStopAuditController extends BasicinfoBaseController {
    private final static Logger logger = LoggerFactory.getLogger(AgencyStopAuditController.class);
    @Autowired
    private IAgencyVerifyService agencyVerifyService;
    @GetMapping("/queryAgencyStopAuditPage")
    public ApiResultDTO queryAgencyStopAuditPage(@RequestHeader("X-Token") String tokenid,
                                                     @RequestParam(value = "page") String page,
                                                     @RequestParam(value = "limit") String limit,
                                                     @RequestParam(value = "flag") String flag,
                                                     @RequestParam(value = "agencyId" , required = false) String agencyId) {
        try {
            UserDTO userDTO = getUser(tokenid);
            Map<String,Object> params=new HashMap<>();
            params.put("agencyId",agencyId);
            params.put("flag",flag);
            params.put("province",userDTO.getProvince());
            PaginationDTO paginationDTO = PageUtils.buildPaginationDTOPage(page, limit);
            PageDTO<AgencyVerify> pageDTO = agencyVerifyService.queryAgencyVerifyData(paginationDTO, params,
                    "id","agency_id","biz_key","agency_code","agency_name","is_deleted","salary_month");
            return ApiResultDTO.success(pageDTO,null);
        } catch (Exception exception) {
            exception.printStackTrace();
            return ApiResultDTO.error(ERROR_RSCODE, "查询数据异常");
        }
    }

    @PostMapping("/agreeStop")
    public ApiResultDTO agreeStop(@RequestHeader("X-Token") String tokenid,
                                  @RequestBody AgencyVerify agencyVerify) {
        try {
            UserDTO userDTO = getUser(tokenid);
            agencyVerify.setStopOperateCode("1");
            agencyVerifyService.updateAgencyVerify(userDTO, agencyVerify);
            return ApiResultDTO.success(null,"已同意停用");
        } catch (Exception exception) {
            exception.printStackTrace();
            return ApiResultDTO.error(ERROR_RSCODE, "操作异常！");
        }
    }

    @PostMapping("/disAgreeStop")
    public ApiResultDTO disAgreeStop(@RequestHeader("X-Token") String tokenid,
                                  @RequestBody AgencyVerify agencyVerify) {
        try {
            UserDTO userDTO = getUser(tokenid);
            agencyVerify.setStopOperateCode("-1");
            agencyVerifyService.updateAgencyVerify(userDTO, agencyVerify);
            return ApiResultDTO.success(null,"已同意停用");
        } catch (Exception exception) {
            exception.printStackTrace();
            return ApiResultDTO.error(ERROR_RSCODE, "操作异常！");
        }
    }
}
